home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VELENG10.ZIP / CMDLINE.C < prev    next >
C/C++ Source or Header  |  1997-07-27  |  3KB  |  82 lines

  1. // ****************************************************************************
  2. // *                                                                          *
  3. // *                      Velena Source Code V1.0                             *
  4. // *                   Written by Giuliano Bertoletti                         *
  5. // *       Based on the knowledged approach of Louis Victor Allis             *
  6. // *   Copyright (C) 1996-97 by Giuliano Bertoletti & GBE 32241 Software PR   *
  7. // *                                                                          *
  8. // ****************************************************************************
  9.  
  10. // Portable engine version.
  11. // read the README file for further informations.
  12.  
  13. // ==========================================================================
  14.  
  15.  
  16. #include <stdio.h>
  17.  
  18. #include "connect4.h"
  19.  
  20. // Here's the interface for sending positions to velena engine
  21. // positions are passed in a C string in the form of: x+y+'0'
  22.  
  23. // where x is a char which defines the level: 'a' = computer weak
  24. // 'b' = computer normal, 'c' = computer strong.
  25.  
  26. // y is a sequence of moves which brings to the wanted position. Columns are
  27. // numbered from 1 to 7.
  28.  
  29. // '0' is the ASCII char 48 which tells Velena to ignore any further character
  30.  
  31. // for example a string like "c4444420" tells velena to analyze the 
  32. // position you reach by placing 5 men in the middle column (3 yellow and 2
  33. // red) and one red man in the second column, and sets velena level to strong.
  34.  
  35. // It's clear from the sequence of moves which side is in turn to move. 
  36.  
  37. // You can pass a position only if you need an answer from the AI core.
  38. // if you pass a position where the game is over you get an error in return.
  39.  
  40. void command_line_input(struct board *board)
  41.    {
  42.    int flag = 1,answer;
  43.    char st[80];
  44.  
  45.    printf("Enter positions in the form x+y+'0', where:\n");
  46.    printf("x is the level of play: 'a' = weak, 'b' = normal, 'c' = strong\n");
  47.    printf("y is a sequence of moves that brings to the position you want\n");
  48.    printf("  (columns are numbered from 1 to 7)\n");
  49.    printf("'0' is the 48 ASCII char which tells Velena where the string ends\n"); 
  50.    printf("\nEnter 'q' to quit\n\n");
  51.  
  52.      do {
  53.         printf(">");   // Waiting for the user to enter the string
  54.         gets(st);
  55.  
  56.         if(st[0]=='q') flag = 0;   // if the string begins with 'q' we quit.
  57.         else {        
  58.              // otherwise we send the string to Velena for parsing...
  59.              answer = playgame(st,board);  
  60.  
  61.              if(answer>0 && answer<=7)   // We made a legal move... 
  62.                  printf("Velena answers in %d\n",answer);        
  63.  
  64.              // We made a syntax error, for example we send a 'g' as a level
  65.              // or we send a 8 as a column number.
  66.              else if(answer==-1) printf("?Syntax error\n");
  67.  
  68.              // We made a positional error, that position is not reachable
  69.              // through a series of legal moves. For example we keep playing
  70.              // after four men have been connected.
  71.              else if(answer==-2) printf("?Positional error\n");
  72.  
  73.              // Actually this is not of much use. We simply close the if-else
  74.              // condition.
  75.              else printf("?Unprintable error");
  76.          }
  77.      } while(flag); // We loop until a quit is forced.
  78.  
  79.    printf("Program terminated\n");
  80.    }
  81.  
  82.